package com.syq.service.impl;

import com.syq.bean.Menu;
import com.syq.dao.MenuDao;
import com.syq.dao.impl.MenuDaoImpl;
import com.syq.service.MenuService;

import java.util.ArrayList;
import java.util.List;

public class MenuServiceImpl implements MenuService {
    private MenuDao menuDao = new MenuDaoImpl();
    @Override
    public List<Menu> getMenuList() {
        List<Menu> menuList = menuDao.getMenuList();//未分级
        List<Menu> newMenuList = new ArrayList<>();//分级后
        for ( Menu m : menuList) {
            if(m.getUpmenuId()==0) {//1级菜单
                List<Menu> secondList = new ArrayList<>();
                for(Menu m2 : menuList) {
                    if(m2.getUpmenuId()==m.getMenuId()) {
                        secondList.add(m2);
                    }
                }
                m.setSecondMenuList(secondList);
                newMenuList.add(m);
            }

        }
        return newMenuList;
    }

    @Override
    public List<Menu> getMenuList(int pageIndex, int pageSize) {
        return menuDao.getMenuList(pageIndex,pageSize);
    }

    @Override
    public int total() {
        return menuDao.total();
    }

    @Override
    public Menu getMenuById(int menuId) {
        return menuDao.getMenuById(menuId);
    }

//    @Override
//    public Menu getUpMenu(int menuId) {
//        return menuDao.getUpMenu(menuId);
//    }

    @Override
    public int updateMenu(int menuId) {
        return menuDao.updateMenu(menuId);
    }
}
